package com.sunsys.QuestionAnswer;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;


public class UserDAO {
	public int login(String userName,String password) {
		ResultSet rs = null;
		int value=0;
		try {
			DBConnection connection = new DBConnection();
			Connection con = connection.makeDBConnection();
			
			String sql = "select * from users where username=\'"+userName+"\' and password=\'"+password +"\'";
			Statement statement = con.createStatement();
			rs = statement.executeQuery(sql);
			
			if(rs.next()== true && userName!="" && password!="") {
				rs = statement.executeQuery("select uid from users");
				if(rs.next()) {
					value = rs.getInt(1);
				}
			}
			else {
				value = 0;
			}
			con.close();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return value;
	}
}

